package com.medicine.service.impl;


import org.springframework.stereotype.Service;

import pagination.Page;
import po.Admin;
import requestvo.AdminReqVo;


@Service
public class AdminService extends BaseServiceImpl{
	public String hasAdmin(String userId, String password) {
		if (userId != null && password != null) {
			try {
				Admin admin=adminDao.get(userId);
				if (admin.getGly_psw().equals(password)) {
					String username= admin.getGly_name();
					return username;
				}
			} catch (Exception e) {
				e.printStackTrace();
				// TODO: handle exception
			}
		}
		return null;
	}
	public String ifHasAdmin(String userId) {
		// TODO 自动生成的方法存根
		if (userId != null) {
			try {
				Admin admin = adminDao.get(userId);
				String username = admin.getGly_name();
				return username;
			} catch (Exception e) {
				e.printStackTrace();
				// TODO: handle exception
			}
		}
		return null;
	}
	public String ifHasAdminName(String gly_name) {
		// TODO 自动生成的方法存根
		if (gly_name != null) {
			try {
				Admin admin = adminDao.getName(gly_name); //查找是否存在有该名字的实验室管理员
				String gly_no = admin.getGly_no(); //返回一个gly_no
				return gly_no;
			} catch (Exception e) {
				e.printStackTrace();
				// TODO: handle exception
			}
		}
		return null;
	}
	public Page findAdminInfo(AdminReqVo adminReqVo) {
		Page<AdminReqVo> page = new Page<>();
		if (adminReqVo.getGly_no() != null
				&& !adminReqVo.getGly_no().equals("")) {
			page.getParams().put("gly_no", adminReqVo.getGly_no());
		}
		if (adminReqVo.getGly_name() != null&& !adminReqVo.getGly_no().equals("")) {
			page.getParams().put("gly_name","%" + adminReqVo.getGly_name() + "%");
		}
		if (adminReqVo.getGly_psw() != null&& !adminReqVo.getGly_psw().equals("")) {
			page.getParams().put("gly_psw", adminReqVo.getGly_psw());
		}
		if (adminReqVo.getGly_tel() != null&& !adminReqVo.getGly_tel().equals("")) {
			page.getParams().put("gly_tel",adminReqVo.getGly_tel());
		}
		/*
		 * if(adminReqVo.getTech_name()!=null&&
		 * !adminReqVo.getTech_no().equals("")){
		 * page.getParams().put("gysfzr", "%"+adminReqVo.getTech_name()+"%");
		 * }
		 */
		page.setPageNo(adminReqVo.getPage());
		page.setPageSize(adminReqVo.getRows());
		page.setResults(adminDao.findPage(page));
		return page;
	}

	public void updateAdminInfo(AdminReqVo adminReqVo) {
		// TODO Auto-generated method stub
		adminDao.update(adminReqVo);

	}

	public void addAdminInfo(AdminReqVo adminReqVo) {
		// TODO Auto-generated method stub
		adminDao.insert(adminReqVo);
	}

	public void delAdminInfo(String[] integers) {
		// TODO Auto-generated method stub
		adminDao.delete(integers);
	}
}
